package com.safewind.wx.constant;

import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.safewind.wx.util.WxUtil;

public class WxConstant {

    private static final Logger logger = LoggerFactory.getLogger(WxUtil.class);

    public static final String AUTH_URL;
    public static final String ACCESS_TOKEN_URL;
    public static final String MENU_CREATE_URL;
    public static final String MESSAGE_CUSTOM_SEND_URL;
    public static final String MEDIA_UPLOAD_URL;
    public static final String GET_WEB_ACCESSTOKEN_URL;
    public static final String REFRESH_WEBTOKEN_URL;
    public static final String CHECK_WEBTOKEN_URL;
    public static final String TEMPLATE_MESSAGE_URL;
    public static final String UPLOAD_MEDIA_URL;
    public static final String DOWNLOAD_MEDIA_URL;

    public static final String APP_ID;
    public static final String APP_SECRET;
    public static final String TOKEN;
    public static final String ENCODING_AES_KEY;

    public static final String JS_API_TICKET_URL;
    public static final String USERINFO_URL;

    public static final String TEMPLATE_ID;

    public static final String WEB_URL;

    static {
        Resource resource = new ClassPathResource("wx.properties");
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");

        Properties properties = null;
        try {
            properties = PropertiesLoaderUtils.loadProperties(encodedResource.getResource());
        } catch (IOException e) {
            logger.error(" 配置文件读取失败#errMsg: " + e.getMessage(), e);
        }
        APP_ID = properties.getProperty("appId");
        APP_SECRET = properties.getProperty("appSecret");
        TOKEN = properties.getProperty("token");
        ENCODING_AES_KEY = properties.getProperty("encodingAESKey");

        AUTH_URL = properties.getProperty("auth_url");
        ACCESS_TOKEN_URL = properties.getProperty("access_token_url");
        MENU_CREATE_URL = properties.getProperty("menu_create_url");
        MESSAGE_CUSTOM_SEND_URL = properties.getProperty("message_custom_send_url");
        MEDIA_UPLOAD_URL = properties.getProperty("media_upload_url");
        GET_WEB_ACCESSTOKEN_URL = properties.getProperty("getwebaccesstoken_url");
        REFRESH_WEBTOKEN_URL = properties.getProperty("refresh_webtoken_url");
        CHECK_WEBTOKEN_URL = properties.getProperty("check_webtoken_url");
        TEMPLATE_MESSAGE_URL = properties.getProperty("template_message_url");
        UPLOAD_MEDIA_URL = properties.getProperty("upload_media_url");
        DOWNLOAD_MEDIA_URL = properties.getProperty("download_media_url");

        JS_API_TICKET_URL = properties.getProperty("js_api_ticket_url");
        USERINFO_URL = properties.getProperty("userinfo_url");

        TEMPLATE_ID = properties.getProperty("template_id");

        WEB_URL = properties.getProperty("web_url");
    }
}
